package com.tanhua.server.controller;

import com.tanhua.server.service.TaoHuaService;
import com.tanhua.server.vo.ErrorResult;
import com.tanhua.server.vo.TaoHuacyvo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RequestMapping
@RestController
public class TaoHuaController {


    @Autowired
    private TaoHuaService taoHuaService;

    /**
     * 发布语音
     *
     * @param soundFile
     *
     * @return
     */
    @PostMapping("peachblossom")
    public ResponseEntity<ErrorResult> saveSound(@RequestParam("soundFile") MultipartFile soundFile) {
        try {

            Boolean bool = this.taoHuaService.saveSound(soundFile);
            if (bool) {
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        //
        ErrorResult errorResult = ErrorResult.builder().errCode("100").errMessage("今日次数已达上限").build();
        return ResponseEntity.status(500).body(errorResult);

    }

    @GetMapping("peachblossom")
    public ResponseEntity<TaoHuacyvo> getSound() {
        try {

            TaoHuacyvo taoHuavo = this.taoHuaService.getSound();
            return ResponseEntity.ok(taoHuavo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
